<template>
  <div class="f2bpm-page-layout">
    <div style="width: 100%; margin: 0px; padding: 0px;text-align: center">
      <div id='title_div'>
        <i class="fa fa-info"></i> 请使用手机扫描下面二维码进行签名：
      </div>
      <div id="qrCodeImg"></div>
      <img id="QrCodeImgPath" :src="QrCodeImgPath" width="200" height="200" style="border: 0px; margin: 3px;" />
      <div id="signimg" style="margin-top: 20px;"></div>
    </div>
  </div>
</template>

<script>
  window.timer1 = null;
  export default {
    created() {
      var that = this;
      var signId = Object.toQueryString("signId");
      var linkType = Object.toQueryString("linkType") || "";
      var linkEntityId = Object.toQueryString("linkEntityId") || "";
      var isreSign = Object.toQueryString("isreSign") || 0;
      that.signId = signId;
      that.linkType = linkType;
      that.linkEntityId = linkEntityId;
      that.isreSign = isreSign;
      that.userId = that.$store.getters.getState.author.userId;
	  var creatorId=that.userId;
      if (isreSign == 1) {
        that.show();
      } else {
		  var url = "#"+__webpath + "/workflow/selector/handsign?linkType=wiid&linkEntityId=" + linkEntityId + "&creatorId=" + creatorId + "&signId=" + signId;
		  window.location.href=url;
        //that.getQrCodeImg();
        //that.setTimerInterval();
      }

    }
    , data() {
      return {
        userId: "",
        signId: "",
        linkType: "",
        linkEntityId: "",
        isreSign: 0,
        QrCodeImgPath:""
      };
    },

    methods: {
      getQrCodeImg() {
        var that = this;
        var res = Object.toAjaxJson("/workflow/selector/", "getHandsignQRCodeData", {
          "signId": that.signId,
          linkEntityId: that.linkEntityId,
          linkType: that.linkType,
          creatorId: that.userId
        });
        if (res.success) {
          that.QrCodeImgPath=res.data;
          //$("#QrCodeImgPath").attr("src", res.data);
        }
      }
      , setTimerInterval() {
        var that = this;
        setTimeout(function () {
          timer1 = setInterval(function () {
            console.info("---获取签名---");
            that.show();
          }, 4000);
        }, 4000);
      }
      , show() {
        var that = this;
        var data = Object.toAjaxJson("/workflow/public/", "getHandSignData", {
          "signId": that.signId
        });
        $("#LoadingDiv").hide();
        if (data.success == true && data.data != "") {
          $("#title_div").html("请点击确认您的签名 <span  class=\"btn btn-minier btn-light cur \" onclick='reSign();'>重新签名</span>");
          $("#QrCodeImgPath").hide();
          var img = new Image();
          img.src = data.data;
          $(img).attr("width", "350");
          $('#signimg').html($(img).prop("outerHTML"));
          clearInterval(timer1);
        } else {
          console.info(data.msg);
        }
        if (data.data == "") {
          $("#title_div").html("请点击确认您的签名 <span  class=\"btn btn-minier btn-light cur \" onclick='reSign();'>重新签名</span>");
        }
      }
      , reSign() {
        var data = Object.toAjaxJson("/workflow/public/", "reSignData", {
          "signId": that.signId
        });
        if (data.success) {
          $("#QrCodeImgPath").show();
          $("#title_div").html("<i class=\"fa fa-info\"></i> 请使用手机扫描下面二维码进行签名：");
          $('#signimg').html("");
          getQrCodeImg();
          setTimerInterval();
        }
      }
      , getResult() {
        return this.signId;
      }
    }
    , mounted() {
      window.myvm = this;
    }
  }

  window.getResult = function () {
    return myvm.getResult();
  }
</script>